package main

import (
	"fmt"
	"gitee.com/shikong-sk/go-wechat-db/model"
	"gitee.com/shikong-sk/go-wechat-db/sqlcipher"
	"gorm.io/gorm"
	"log"
	"os"
	"path"
	"path/filepath"
)

func main() {
	workdir, err := os.Getwd()
	if err != nil {
		return
	}

	dbFile, _ := filepath.Abs(path.Join(workdir, "EnMicroMsg.db"))
	// 数据库密钥
	dbKey := "*******"

	db, err := gorm.Open(sqlcipher.Open(dbFile), &gorm.Config{})

	if err != nil {
		log.Fatalln(err.Error())
	}
	fmt.Printf("%#v\n", db)

	// 数据库参数
	db.Exec(fmt.Sprintf("PRAGMA key = '%s';", dbKey))
	db.Exec("PRAGMA cipher_use_hmac = OFF;")
	db.Exec("PRAGMA cipher_page_size = 1024;")
	db.Exec("PRAGMA kdf_iter = 4000;")

	result := make([]model.SqliteMaster, 5)
	// sqlite 系统表
	res := db.Table("sqlite_master").Find(&result)

	fmt.Println(res.RowsAffected)

	for i := 0; i < len(result); i++ {
		fmt.Printf("%#v\n", result[i])
	}
}
